package com.vcredit.creditcat.service;

import com.vcredit.creditcat.framework.pagination.Criteria;
import com.vcredit.creditcat.framework.pagination.Page;
import com.vcredit.creditcat.model.ProcessSpecialCondition;
import com.vcredit.creditcat.persistence.base.ProcessSpecialConditionMapper;
import com.vcredit.creditcat.vo.ProcessSpecialConditionVo;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/*
 * @author zhangxingong
 * @version 1.0
 * @since 1.0
*/
@Service
public class ProcessSpecialConditionService {

  @Autowired
  private ProcessSpecialConditionMapper processSpecialConditionMapper;

  public Page<ProcessSpecialCondition> findByPage(Criteria criteria) {
    return new Page<ProcessSpecialCondition>(
        processSpecialConditionMapper.findByPageCount(criteria),
        processSpecialConditionMapper.findByPage(criteria));
  }

  public List<ProcessSpecialCondition> find(ProcessSpecialCondition processSpecialCondition) {
    return processSpecialConditionMapper.find(processSpecialCondition);
  }

  public ProcessSpecialCondition findById(Long specialConditionId) {
    return processSpecialConditionMapper.findById(specialConditionId);
  }

  public List<ProcessSpecialCondition> findAll() {
    return processSpecialConditionMapper.findAll();
  }

  public void save(ProcessSpecialConditionVo processSpecialConditionVo) {
    try {
      ProcessSpecialCondition processSpecialCondition = new ProcessSpecialCondition();
      BeanUtils.copyProperties(processSpecialCondition, processSpecialConditionVo);
      processSpecialConditionMapper.insert(processSpecialCondition);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void update(ProcessSpecialCondition processSpecialCondition) {
    processSpecialConditionMapper.update(processSpecialCondition);
  }

  public void removeProcessSpecialCondition(String ids) {
    for (String specialConditionIdString : ids.split(",")) {
      Long specialConditionId = Long.parseLong(specialConditionIdString);
      processSpecialConditionMapper.delete(specialConditionId);
    }
  }

}
